package com.ipcoder;

import java.io.IOException;
import java.io.OutputStream;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.Socket;
import java.net.SocketException;
import java.util.Scanner;

public class Recive {
    public static void main(String[] args) throws IOException {
        Scanner sc=new Scanner(System.in);
        //创建接收端的socket套接字
        DatagramSocket js = new DatagramSocket(9998);
        while (true) {
            System.out.println("接收的消息:");
            byte[] bt = new byte[4096];
            //创建接收包
            DatagramPacket jieshou = new DatagramPacket(bt, bt.length);
            //接收字节数组
            js.receive(jieshou);
            //打印接受的内容
            System.out.println(new String(jieshou.getData() ,0,jieshou.getLength()));
            js.close();
            Socket sk=new Socket("192.168.18.24",9998);
            OutputStream os=sk.getOutputStream();
            os.write(("数据已经收到了:"+sc.nextLine()).getBytes());

            os.close();
            sk.close();
        }
        //js.close();

    }
}
